import React, { useState } from 'react'
import { Button } from 'antd-mobile'

export default function ButtonAgain(props) {
    const options = { ...props };
    const { fn } = options;
    let [isLoading, setLoading] = useState(false);

    if (fn) delete options.fn;


    const click = async () => {
        setLoading(true);
        await fn();
        setLoading(false);
    }

    return (
        <Button {...options} loading={isLoading} onClick={click} color='primary'>{props.children}</Button>
    )
}
